<%-- 
    Document   : register
    Created on : Dec 18, 2013, 3:42:11 PM
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../Include/header.jsp" %>

<script type="text/javascript">
    function clickCaret(){
        if($(".user .dropdown-menu").hasClass("show")){
            $(".user .dropdown-menu").removeClass("show");
        }else{
            $(".user .dropdown-menu").addClass("show");
        }
    }
</script>
<script type="text/javascript">
    function checkValidUsername(username){
        var regex = new RegExp("^[a-zA-Z0-9]([._](?![._])|[a-zA-Z0-9]){6,28}[a-zA-Z0-9]$");
        return regex.test(username);
    }

    function checkValidPassword(password){
        var regex = new RegExp("^.{6,30}$");
        return regex.test(password);
    }

    function checkValidEmail(email){
        var regex = new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");
        return regex.test(email);
    }

    function checkValidFullname(fullname){
        var regex = new RegExp("^([ ](?![ ])|[a-zA-ZàáạảãâầấậẩẫăằắặẳẵèéẹẻẽêềếệểễìíịỉĩòóọỏõôồốộổỗơờớợởỡùúụủũưừứựửữỳýỵỷỹÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠỲÝỴỶỸĐđ]){3,98}$");
        return regex.test(fullname);
    }

    function checkValidConfirm(confirm, password){
        return confirm === password;
    }

    function checkValidRegister(){
        var username = document.getElementById("username").value;
        var password = document.getElementById("password").value;
        var confirm = document.getElementById("confirm").value;
        var fullname = document.getElementById("fullname").value;
        var email = document.getElementById("email").value;
        var check = document.getElementById("rule-check").checked;

        if(!check){
            document.getElementById("non-check-rule").classList.remove("hidden");
            return false;
        }else{
            if(!document.getElementById("non-check-rule").classList.contains("hidden")){
                document.getElementById("non-check-rule").classList.add("hidden");
            }
        }

        if(!checkValidUsername(username)){
            document.getElementById("invalid-username").classList.remove("hidden");
            return false;
        }else{
            if(!document.getElementById("invalid-username").classList.contains("hidden")){
                document.getElementById("invalid-username").classList.add("hidden");
            }
        }

        if(!checkValidPassword(password)){
            document.getElementById("invalid-password").classList.remove("hidden");
            return false;
        }else{
            if(!document.getElementById("invalid-password").classList.contains("hidden")){
                document.getElementById("invalid-password").classList.add("hidden");
            }
        }

        if(!checkValidConfirm(confirm, password)){
            document.getElementById("invalid-confirm").classList.remove("hidden");
            return false;
        }else{
            if(!document.getElementById("invalid-confirm").classList.contains("hidden")){
                document.getElementById("invalid-confirm").classList.add("hidden");
            }
        }

        if(!checkValidFullname(fullname)){
            document.getElementById("invalid-fullname").classList.remove("hidden");
            return false;
        }else{
            if(!document.getElementById("invalid-fullname").classList.contains("hidden")){
                document.getElementById("invalid-fullname").classList.add("hidden");
            }
        }


        if(!checkValidEmail(email)){
            document.getElementById("invalid-email").classList.remove("hidden");
            return false;
        }else{
            if(!document.getElementById("invalid-email").classList.contains("hidden")){
                document.getElementById("invalid-email").classList.add("hidden");
            }
        }



        return true;
    }   
</script>


<c:choose>
    <c:when test="${not empty sessionScope.USER}">
        <c:redirect url="Home"/>
    </c:when>
    <c:otherwise>
        



        <div class="container">
            <div class="row">
                <div class="register-rule register-rule-warning col-xs-6">
                    <div class="register-rule-heading"><h3 class="register-rule-title">Điều Khoản</h3></div>
                    <div class="register-rule-body  scrollable-y">
                        <p>
                            sdasda asd ad aasda   asd   asdasdasdsadsd as d sadasdasd  sdasdsadas  sadasdasd asd
                            sadsadsad asdsadsad  sadasdasd asdsadsad asdasdasd sadasdsadasdasdsad sdasdsadsd asdsad asdasd 
                            asdasasd asdasd  asdasddsad  asdasdsadsad asdasdasdsad 
                        </p>
                        <p>
                            sdasda asd ad aasda   asd   asdasdasdsadsd as d sadasdasd  sdasdsadas  sadasdasd asd
                            sadsadsad asdsadsad  sadasdasd asdsadsad asdasdasd sadasdsadasdasdsad sdasdsadsd asdsad asdasd 
                            asdasasd asdasd  asdasddsad  asdasdsadsad asdasdasdsad 
                        </p>
                        <p>
                            sdasda asd ad aasda   asd   asdasdasdsadsd as d sadasdasd  sdasdsadas  sadasdasd asd
                            sadsadsad asdsadsad  sadasdasd asdsadsad asdasdasd sadasdsadasdasdsad sdasdsadsd asdsad asdasd 
                            asdasasd asdasd  asdasddsad  asdasdsadsad asdasdasdsad 
                        </p>
                        <p>
                            sdasda asd ad aasda   asd   asdasdasdsadsd as d sadasdasd  sdasdsadas  sadasdasd asd
                            sadsadsad asdsadsad  sadasdasd asdsadsad asdasdasd sadasdsadasdasdsad sdasdsadsd asdsad asdasd 
                            asdasasd asdasd  asdasddsad  asdasdsadsad asdasdasdsad 
                        </p>
                        <p>
                            sdasda asd ad aasda   asd   asdasdasdsadsd as d sadasdasd  sdasdsadas  sadasdasd asd
                            sadsadsad asdsadsad  sadasdasd asdsadsad asdasdasd sadasdsadasdasdsad sdasdsadsd asdsad asdasd 
                            asdasasd asdasd  asdasddsad  asdasdsadsad asdasdasdsad 
                        </p>
                    </div>
                    <div class="register-rule-footer">
                        <input type="checkbox" id="rule-check" name="checkbox" /> Tôi đồng ý
                        <span id="non-check-rule" class="invalid-mess hidden" style="margin-left: 50px;">Bạn phải đồng ý các điều khoản trước khi đăng ký</span>
                    </div>
                </div>
                <div class="login login-warning register">
                    <div class="login-heading"><h3 class="login-title">Đăng Ký
                            <c:if test="${not empty requestScope.MESSAGE_REGISTER_FAIL}">
                                <p class="invalid-mess">${requestScope.MESSAGE_REGISTER_FAIL}</p>
                            </c:if>
                        </h3></div>
                    <div class="login-body">
                        <form class="form-horizontal" role="form" onsubmit="return checkValidRegister()" action="User" method="POST">
                            <!-- <p class="invalid-mess text-center">Invalid information</p> -->
                            <div class="form-group">
                                <label class="col-md-4 control-label">Tên Đăng Nhập</label>
                                <div class="col-md-8">
                                    <input type="text" class="form-control" id="username" placeholder="Tên đăng nhập" name="username" value="">
                                    <c:if test="${not empty requestScope.MESSAGE_USER_FAIL}">
                                        <br/><p class="invalid-mess">${requestScope.MESSAGE_USER_FAIL}</p>
                                    </c:if>
                                </div>
                            </div>
                            <div class="col-md-offset-4">
                                <p class="invalid-mess hidden" id="invalid-username">Tên đăng nhập không hợp lệ!</p>
                            </div>
                            <div class="form-group">
                                <label class="col-md-4 control-label">Mật Khẩu</label>
                                <div class="col-md-8">
                                    <input type="password" class="form-control" id="password" placeholder="Mật khẩu" name="password" value="" >
                                    <c:if test="${not empty requestScope.MESSAGE_PASSWORD_FAIL}">
                                        <br/><p class="invalid-mess">${requestScope.MESSAGE_PASSWORD_FAIL}</p>
                                    </c:if>
                                </div>
                            </div>
                            <div class="col-md-offset-4">
                                <p class="invalid-mess hidden" id="invalid-password">Mật khẩu không hợp lệ!</p>
                            </div>
                            <div class="form-group">
                                <label class="col-md-4 control-label">Nhập lại mật khẩu</label>
                                <div class="col-md-8">
                                    <input type="password" class="form-control" id="confirm" placeholder="Nhập lại mật khẩu" name="confirm" value="">
                                    <c:if test="${not empty requestScope.MESSAGE_CONFIRM_FAIL}">
                                        <br/><p class="invalid-mess">${requestScope.MESSAGE_CONFIRM_FAIL}</p>
                                    </c:if>
                                </div>
                            </div>
                            <div class="col-md-offset-4">
                                <p class="invalid-mess hidden" id="invalid-confirm">Nhập lại mật khẩu không đúng</p>
                            </div>
                            <div class="form-group">
                                <label class="col-md-4 control-label">Họ Tên</label>
                                <div class="col-md-8">
                                    <input type="text" class="form-control" id="fullname" placeholder="Họ tên" name="fullName" value="" >
                                <c:if test="${not empty requestScope.MESSAGE_FULLNAME_FAIL}">
                                        <br/><p class="invalid-mess">${requestScope.MESSAGE_FULLNAME_FAIL}</p>
                                    </c:if>
                                </div>
                            </div>
                            <div class="col-md-offset-4">
                                <p class="invalid-mess hidden" id="invalid-fullname">Họ tên không hợp lệ!</p>
                            </div>
                            <div class="form-group">
                                <label class="col-md-4 control-label">Email</label>
                                <div class="col-md-8">
                                    <input type="text" class="form-control" id="email" placeholder="Email" name="email" value="">
                                <c:if test="${not empty requestScope.MESSAGE_EMAIL_FAIL}">
                                        <br/><p class="invalid-mess">${requestScope.MESSAGE_EMAIL_FAIL}</p>
                                    </c:if>
                                </div>
                            </div>
                            <div class="col-md-offset-4">
                                <p class="invalid-mess hidden" id="invalid-email">Email không hợp lệ</p>
                            </div>
                            <div class="form-group">
                                <div class="col-md-offset-7 col-md-2">
                                    <input class="btn btn-warning" type="reset" value="Nhập Lại">
                                </div>
                                <div class="col-md-3">
                                    <input type="hidden" name="action" value="Register" />
                                    <input type="submit" value="Đăng Ký" class="btn btn-success" />
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </c:otherwise>
</c:choose>




<%@include file="../Include/footer.jsp" %>
